<template>
  <div class="chart-container" ref="chartRef"></div>
</template>

<script lang="ts">
export default {
  name: "LineChart",
};
</script>

<script lang="ts" setup>
/*
    1. 下载echarts
      npm i echarts
    2. 引入echarts
      import * as echarts from 'echarts'
    3. 准备具备宽高的DOM容器
    4. 生成图表
      创建echarts实例
      定义图表option
      渲染图表
  */
import * as echarts from "echarts";
import { onMounted, ref } from "vue";

const chartRef = ref();

onMounted(() => {
  const myEcharts = echarts.init(chartRef.value);
  const option = {
    xAxis: {
      data: [
        "一月",
        "二月",
        "三月",
        "四月",
        "五月",
        "六月",
        "七月",
        "八月",
        "九月",
        "十月",
        "十一月",
        "十二月",
      ],
      // 坐标轴左右留白
      boundaryGap: false,
    },
    yAxis: {
      // 隐藏
      show: false,
    },
    tooltip: {},
    series: {
      type: "line",
      data: [25, 15, 46, 20, 14, 35, 15, 46, 20, 34, 34, 13],
      // 平滑曲线显示
      smooth: true,
      // 拐点样式
      itemStyle: {
        opacity: 0,
      },
      // 区域样式
      areaStyle: {
        color: "#a64ca6",
        opacity: 1,
      },
      // 折线样式
      lineStyle: {
        color: "#a64ca6",
      },
    },
    grid: {
      top: 0,
      bottom: 0,
      left: 0,
      right: 0,
    },
  };
  myEcharts.setOption(option);
});
</script>

<style scoped>
.chart-container {
  height: 100%;
}
</style>
